home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / m4-1_0_3.lha / m4-1.0.3 / m4.info-2 (.txt) < prev    next >
GNU Info File  |  1992-12-19  |  36KB  |  788 lines

  1. This is Info file m4.info, produced by Makeinfo-1.47 from the input
  2. file ./m4.texinfo.
  3.    This file documents the GNU m4 utility.
  4.    Copyright (C) 1989-1992 Free Software Foundation, Inc.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided also
  10. that the entire resulting derived work is distributed under the terms
  11. of a permission notice identical to this one.
  12.    Permission is granted to copy and distribute translations of this
  13. manual into another language, under the above conditions for modified
  14. versions.
  15. File: m4.info,  Node: Divert,  Next: Undivert,  Prev: Diversions,  Up: Diversions
  16. Diverting output
  17. ================
  18.    Output is diverted using `divert':
  19.      divert(opt NUMBER)
  20. where NUMBER is the diversion to be used.  If NUMBER is left out, it is
  21. assumed to be zero.
  22.    The expansion of `divert' is void.
  23.    Diverted output, that hasn't been explicitly undiverted, will be
  24. undiverted when all the input has been processed.
  25.      divert(1)
  26.      This text is diverted.
  27.      divert
  28.      =>
  29.      This text is not diverted.
  30.      =>This text is not diverted.
  31.      ^D
  32.      =>
  33.      =>This text is diverted.
  34.    Several calls of `divert' with the same argument do not overwrite
  35. the previous diverted text, but append to it.
  36.    If output is diverted to an non-existent diversion, it is simply
  37. discarded.  This can be used to suppress unwanted output.  A common
  38. example of unwanted output is the trailing newlines after macro
  39. definitions.  Here is how to avoid them.
  40.      divert(-1)
  41.      define(`foo', `Macro `foo'.')
  42.      define(`bar', `Macro `bar'.')
  43.      divert
  44.      =>
  45.    This is a common programming idiom in `m4'.
  46. File: m4.info,  Node: Undivert,  Next: Divnum,  Prev: Divert,  Up: Diversions
  47. Undiverting output
  48. ==================
  49.    Diverted text can be undiverted explicitly using the built-in
  50. `undivert':
  51.      undivert(opt NUMBER, ...)
  52. which undiverts the diversions given by the arguments, in the order
  53. given.  If no arguments are supplied, all diversions are undiverted, in
  54. numerical order.
  55.    The expansion of `undivert' is void.
  56.      divert(1)
  57.      This text is diverted.
  58.      divert
  59.      =>
  60.      This text is not diverted.
  61.      =>This text is not diverted.
  62.      undivert(1)
  63.      =>
  64.      =>This text is diverted.
  65.      =>
  66.    Notice the last two blank lines.  One of them comes from the newline
  67. following `undivert', the other from the newline that followed the
  68. `divert'!  A diversion often starts with a blank line like this.
  69.    When diverted text is undiverted, it is *not* reread by `m4', but
  70. rather copied directly to the current output, and it is therefore not
  71. an error to undivert into a diversion.
  72.    When a diversion has been undiverted, the diverted text is discarded,
  73. and it is not possible to bring back diverted text more than once.
  74.      divert(1)
  75.      This text is diverted first.
  76.      divert(0)undivert(1)dnl
  77.      =>
  78.      =>This text is diverted first.
  79.      undivert(1)
  80.      =>
  81.      divert(1)
  82.      This text is also diverted but not appended.
  83.      divert(0)undivert(1)dnl
  84.      =>
  85.      =>This text is also diverted but not appended.
  86.    Attempts to undivert the current diversion are silently ignored.
  87.    GNU `m4' allows named files to be undiverted.  Given a non-numeric
  88. argument, the contents of the file named will be copied, uninterpreted,
  89. to the current output.  This complements the built-in `include' (*note
  90. Include::.).  To illustrate the difference, assume the file `foo'
  91. contains the word `bar':
  92.      define(`bar', `BAR')
  93.      =>
  94.      undivert(`foo')
  95.      =>bar
  96.      =>
  97.      include(`foo')
  98.      =>BAR
  99.      =>
  100. File: m4.info,  Node: Divnum,  Next: Cleardiv,  Prev: Undivert,  Up: Diversions
  101. Diversion numbers
  102. =================
  103.    The built-in `divnum':
  104.      divnum
  105. expands to the number of the current diversion.
  106.      Initial divnum
  107.      =>Initial 0
  108.      divert(1)
  109.      Diversion one: divnum
  110.      divert(2)
  111.      Diversion two: divnum
  112.      divert
  113.      =>
  114.      ^D
  115.      =>
  116.      =>Diversion one: 1
  117.      =>
  118.      =>Diversion two: 2
  119.    The last call of `divert' without argument is necessary, since the
  120. undiverted text would otherwise be diverted itself.
  121. File: m4.info,  Node: Cleardiv,  Prev: Divnum,  Up: Diversions
  122. Discarding diverted text
  123. ========================
  124.    Often it is not known, when output is diverted, whether the diverted
  125. text is actually needed.  Since all non-empty diversion are brought back
  126. when the end of input is seen, a method of discarding a diversion is
  127. needed.  If all diversions should be discarded, the easiest is to end
  128. the input to `m4' with `divert(-1)':
  129.      divert(1)
  130.      Diversion one: divnum
  131.      divert(2)
  132.      Diversion two: divnum
  133.      divert(-1)
  134.      ^D
  135. No output is produced at all.
  136.    Clearing selected diversions can be done with the following macro:
  137.      define(`cleardivert',
  138.      `pushdef(`_num', divnum)divert(-1)undivert($@)divert(_num)popdef(`_num')')
  139.      =>
  140.    It is called just like `undivert', but the effect is to clear the
  141. diversions, given by the arguments.  (This macro has a nasty bug!  You
  142. should try to see if you can find it and correct it.)
  143. File: m4.info,  Node: Text handling,  Next: Arithmetic,  Prev: Diversions,  Up: Top
  144. Macros for text handling
  145. ************************
  146.    There are a number of built-ins in `m4' for manipulating text in
  147. various ways, extracting substrings, searching, substituting, and so on.
  148. * Menu:
  149. * Len::                         Calculating length of strings
  150. * Index::                       Searching for substrings
  151. * Regexp::                      Searching for regular expressions
  152. * Substr::                      Extracting substrings
  153. * Translit::                    Translating characters
  154. * Patsubst::                    Substituting text by regular expression
  155. * Format::                      Formatting strings (printf-like)
  156. File: m4.info,  Node: Len,  Next: Index,  Prev: Text handling,  Up: Text handling
  157. Calculating length of strings
  158. =============================
  159.    The length of a string can be calculated by `len':
  160.      len(STRING)
  161. which expands to the length of STRING, as a decimal number.
  162.      len()
  163.      =>0
  164.      len(`abcdef')
  165.      =>6
  166. File: m4.info,  Node: Index,  Next: Regexp,  Prev: Len,  Up: Text handling
  167. Searching for substrings
  168. ========================
  169.    Searching for substrings is done with `index':
  170.      index(STRING, SUBSTRING)
  171. which expands to the index of the first occurrence of SUBSTRING in
  172. STRING.  The first character in STRING has index 0.  If SUBSTRING does
  173. not occur in STRING, `index' expands to `-1'.
  174.      index(`gnus, gnats, and armadillos', `nat')
  175.      =>7
  176.      index(`gnus, gnats, and armadillos', `dag')
  177.      =>-1
  178. File: m4.info,  Node: Regexp,  Next: Substr,  Prev: Index,  Up: Text handling
  179. Searching for regular expressions
  180. =================================
  181.    Searching for regular expressions is done with the built-in `regexp':
  182.      regexp(STRING, REGEXP, opt REPLACEMENT)
  183. which searches for REGEXP in STRING.  The syntax for regular
  184. expressions is the same as in GNU Emacs.  *Note Syntax of Regular
  185. Expressions: (emacs)Regexps.
  186.    If REPLACEMENT is omitted, `regexp' expands to the index of the
  187. first match of REGEXP in STRING.  If REGEXP does not match anywhere in
  188. STRING, it expands to -1.
  189.      regexp(`GNUs not Unix', `\<[a-z]\w+')
  190.      =>5
  191.      regexp(`GNUs not Unix', `\<Q\w*')
  192.      =>-1
  193.    If REPLACEMENT is supplied, `regexp' changes the expansion to this
  194. argument, with `\&' substituted by STRING, and `\N' substituted by the
  195. text matched by the Nth parenthesized sub-expression of REGEXP, `\0'
  196. being the text the entire regular expression matched.
  197.      regexp(`GNUs not Unix', `\w\(\w+\)$', `*** \0 *** \1 ***')
  198.      =>*** Unix *** nix ***
  199. File: m4.info,  Node: Substr,  Next: Translit,  Prev: Regexp,  Up: Text handling
  200. Extracting substrings
  201. =====================
  202.    Substrings are extracted with `substr':
  203.      substr(STRING, FROM, opt LENGTH)
  204. which expands to the substring of STRING, which starts at index FROM,
  205. and extends for LENGTH characters, or to the end of STRING, if LENGTH
  206. is omitted.  The starting index of a string is always 0.
  207.      substr(`gnus, gnats, and armadillos', 6)
  208.      =>gnats, and armadillos
  209.      substr(`gnus, gnats, and armadillos', 6, 5)
  210.      =>gnats
  211. File: m4.info,  Node: Translit,  Next: Patsubst,  Prev: Substr,  Up: Text handling
  212. Translating characters
  213. ======================
  214.    Character translation is done with `translit':
  215.      translit(STRING, CHARS, REPLACEMENT)
  216. which expands to STRING, with each character that occurs in CHARS
  217. translated into the character from REPLACEMENT with the same index.
  218.    If REPLACEMENT is shorter than CHARS, the excess characters are
  219. deleted from the expansion.  If REPLACEMENT is omitted, all characters
  220. in STRING, that are present in CHARS are deleted from the expansion.
  221.    Both CHARS and REPLACEMENT can contain character-ranges, e.g., `a-z'
  222. (meaning all lowercase letters) or `0-9' (meaning all digits).  To
  223. include a dash `-' in CHARS or REPLACEMENT, place it first or last.
  224.    It is not an error for the last character in the range to be `larger'
  225. than the first.  In that case, the range runs backwards, i.e., `9-0'
  226. means the string `9876543210'.
  227.      translit(`GNUs not Unix', `A-Z')
  228.      =>s not nix
  229.      translit(`GNUs not Unix', `a-z', `A-Z')
  230.      =>GNUS NOT UNIX
  231.      translit(`GNUs not Unix', `A-Z', `z-a')
  232.      =>tmfs not fnix
  233.    The first example deletes all uppercase letters, the second converts
  234. lowercase to uppercase, and the third `mirrors' all uppercase letters,
  235. while converting them to lowercase.  The two first cases are by far the
  236. most common.
  237. File: m4.info,  Node: Patsubst,  Next: Format,  Prev: Translit,  Up: Text handling
  238. Substituting text by regular expression
  239. =======================================
  240.    Global substitution in a string is done by `patsubst':
  241.      patsubst(STRING, REGEXP, opt REPLACEMENT)
  242. which searches STRING for matches of REGEXP, and substitutes
  243. REPLACEMENT for each match.  The syntax for regular expressions is the
  244. same as in GNU Emacs.
  245.    The parts of STRING that are not covered by any match of REGEXP are
  246. copied to the expansion.  Whenever a match is found, the search
  247. proceeds from the end of the match, so a character from STRING will
  248. never be substituted twice.  If REGEXP matches a string of zero length,
  249. the start position for the search is incremented, to avoid infinite
  250. loops.
  251.    When a replacement is to be made, REPLACEMENT is inserted into the
  252. expansion, with `\&' substituted by STRING, and `\N' substituted by the
  253. text matched by the Nth parenthesized sub-expression of REGEXP, `\0'
  254. being the text the entire regular expression matched.
  255.    The REPLACEMENT argument can be omitted, in which case the text
  256. matched by REGEXP is deleted.
  257.      patsubst(`GNUs not Unix', `^', `OBS: ')
  258.      =>OBS: GNUs not Unix
  259.      patsubst(`GNUs not Unix', `\<', `OBS: ')
  260.      =>OBS: GNUs OBS: not OBS: Unix
  261.      patsubst(`GNUs not Unix', `\w*', `(\0)')
  262.      =>(GNUs)() (not)() (Unix)
  263.      patsubst(`GNUs not Unix', `\w+', `(\0)')
  264.      =>(GNUs) (not) (Unix)
  265.      patsubst(`GNUs not Unix', `[A-Z][a-z]+')
  266.      =>GN not
  267.    Here is a slightly more realistic example, which capitalizes
  268. individual word or whole sentences, by substituting calls of the macros
  269. `upcase' and `downcase' into the strings.
  270.      define(`upcase', `translit(`$*', `a-z', `A-Z')')dnl
  271.      define(`downcase', `translit(`$*', `A-Z', `a-z')')dnl
  272.      define(`capitalize1',
  273.           `regexp(`$1', `^\(\w\)\(\w*\)', `upcase(`\1')`'downcase(`\2')')')dnl
  274.      define(`capitalize',
  275.           `patsubst(`$1', `\w+', `capitalize1(`\0')')')dnl
  276.      capitalize(`GNUs not Unix')
  277.      =>Gnus Not Unix
  278. File: m4.info,  Node: Format,  Prev: Patsubst,  Up: Text handling
  279. Formatted output
  280. ================
  281.    Formatted output can be made with `format':
  282.      format(FORMAT-STRING, ...)
  283. which works much like the C function `printf'.  The first argument is a
  284. format string, which can contain `%' specifications, and the expansion
  285. of `format' is the formatted string.
  286.    Its use is best described by a few examples:
  287.      define(`foo', `The brown fox jumped over the lazy dog')
  288.      =>
  289.      format(`The string "%s" is %d characters long', foo, len(foo))
  290.      =>The string "The brown fox jumped over the lazy dog" is 38 characters long
  291.    Using the `forloop' macro defined in *Note Loops::, this example
  292. shows how `format' can be used to produce tabular output.
  293.      forloop(`i', 1, 10, `format(`%6d squared is %10d
  294.      ', i, eval(i^2))')
  295.      =>     1 squared is        1
  296.      =>     2 squared is        4
  297.      =>     3 squared is        9
  298.      =>     4 squared is       16
  299.      =>     5 squared is       25
  300.      =>     6 squared is       36
  301.      =>     7 squared is       49
  302.      =>     8 squared is       64
  303.      =>     9 squared is       81
  304.      =>    10 squared is      100
  305.    The built-in `format' is modeled after the ANSI C `printf' function,
  306. and supports the normal `%' specifiers: `c', `s', `d', `o', `x', `X',
  307. `u', `e', `E' and `f'; it supports field widths and precisions, and the
  308. modifiers `+', `-', ` ', `0', `#', `h' and `l'.  For more details on
  309. the functioning of `printf', see the C Library Manual.
  310. File: m4.info,  Node: Arithmetic,  Next: Unix commands,  Prev: Text handling,  Up: Top
  311. Macros for doing arithmetic
  312. ***************************
  313.    Integer arithmetic is included in `m4', with a C-like syntax.  As
  314. convenient shorthands, there are built-ins for simple increment and
  315. decrement operations.
  316. * Menu:
  317. * Incr::                        Decrement and increment operators
  318. * Eval::                        Evaluating integer expressions
  319. File: m4.info,  Node: Incr,  Next: Eval,  Prev: Arithmetic,  Up: Arithmetic
  320. Decrement and increment operators
  321. =================================
  322.    Increment and decrement of integers are supported using the built-ins
  323. `incr' and `decr':
  324.      incr(NUMBER)
  325.      decr(NUMBER)
  326. which expand to the numerical value of NUMBER, incremented, or
  327. decremented, respectively, by one.
  328.      incr(4)
  329.      =>5
  330.      decr(7)
  331.      =>6
  332. File: m4.info,  Node: Eval,  Prev: Incr,  Up: Arithmetic
  333. Evaluating integer expressions
  334. ==============================
  335.    Integer expressions are evaluated with `eval':
  336.      eval(EXPRESSION, opt RADIX, opt WIDTH)
  337. which expands to the value of EXPRESSION.
  338.    Expressions can contain the following operators, listed in order of
  339. decreasing precedence.
  340.      Unany minus
  341. `**  ^'
  342.      Exponentiation
  343. `*  /  %'
  344.      Multiplication, division and modulo
  345. `+  -'
  346.      Addition and subtraction
  347. `==  !=  >  >=  <  <='
  348.      Relational operators
  349.      Logical negation
  350.      Bitwise and
  351.      Bitwise or
  352.      Logical and
  353.      Logical or
  354.    All operators, except exponentiation, are left associative.
  355.    Numbers can be given in decimal, octal (starting with `0'), or
  356. hexadecimal (starting with `0x').
  357.    Parentheses may be used to group subexpressions whenever needed. 
  358. For the relational operators, a true relation returns `1', and a false
  359. relation return `0'.
  360.    Here are a few examples of use of `eval'.
  361.      eval(-3 * 5)
  362.      =>-15
  363.      eval(index(`Hello world', `llo') >= 0)
  364.      =>1
  365.      define(`square', `eval(($1)^2)')
  366.      =>
  367.      square(9)
  368.      =>81
  369.      square(square(5)+1)
  370.      =>676
  371.      define(`foo', `666')
  372.      =>
  373.      eval(`foo'/6)
  374.      error-->m4:51.eval:14: bad expression in eval: foo/6
  375.      =>
  376.      eval(foo/6)
  377.      =>111
  378.    As the second to last example shows, `eval' does not handle macro
  379. names, even if they expand to a valid expression (or part of a valid
  380. expression).  Therefore all macros must be expanded before they are
  381. passed to `eval'.
  382.    If RADIX is specified, it specifies the radix to be used in the
  383. expansion.  The default radix is 10.  The result of `eval' is always
  384. taken to be signed.  The WIDTH argument specifies a minimum output
  385. width.  The result is zero-padded to extend the expansion to the
  386. requested width.
  387.      eval(666, 10)
  388.      =>666
  389.      eval(666, 11)
  390.      =>556
  391.      eval(666, 6)
  392.      =>3030
  393.      eval(666, 6, 10)
  394.      =>0000003030
  395.      eval(-666, 6, 10)
  396.      =>-000003030
  397.    Please take note that RADIX cannot be larger than 36 in the current
  398. implemention.  Which characters can be used as digits, if the radix is
  399. larger than 36?  Currently any radix larger than 36 are rejected.
  400. File: m4.info,  Node: Unix commands,  Next: Miscellaneous,  Prev: Arithmetic,  Up: Top
  401. Running Unix commands
  402. *********************
  403.    There are a few built-in macros in `m4' that allow you to run Unix
  404. commands from within `m4'.
  405. * Menu:
  406. * Syscmd::                      Executing simple commands
  407. * Esyscmd::                     Reading the output of commands
  408. * Sysval::                      Exit codes
  409. * Maketemp::                    Making names for temporary files
  410. File: m4.info,  Node: Syscmd,  Next: Esyscmd,  Prev: Unix commands,  Up: Unix commands
  411. Executing simple commands
  412. =========================
  413.    Any shell command can be executed, using `syscmd':
  414.      syscmd(SHELL-COMMAND)
  415. which executes SHELL-COMMAND as a shell command.
  416.    The expansion of `syscmd' is void.
  417.    The expansion is *not* the output from the command!  Instead the
  418. standard input, output and error of the command are the same as those of
  419. `m4'.  This means that output or error messages from the commands are
  420. not read by `m4', and might get mixed up with the normal output from
  421. `m4'.  This can produce unexpected results.  It is therefore a good
  422. habit to always redirect the input and output of shell commands used
  423. with `syscmd'.
  424. File: m4.info,  Node: Esyscmd,  Next: Sysval,  Prev: Syscmd,  Up: Unix commands
  425. Reading the output of commands
  426. ==============================
  427.    If you want `m4' to read the output of a Unix command, use `esyscmd':
  428.      esyscmd(SHELL-COMMAND)
  429. which expands to the standard output of the shell command SHELL-COMMAND.
  430.    The error output of SHELL-COMMAND is not a part of the expansion. It
  431. will appear along with the error output of `m4'.  Assume you are
  432. positioned into the `checks' directory of GNU `m4' distribution, then:
  433.      define(`vice', `esyscmd(grep Vice COPYING)')
  434.      =>
  435.      vice
  436.      =>  Ty Coon, President of Vice
  437.      =>
  438.    Note how the expansion of `esyscmd' has a trailing newline.
  439. File: m4.info,  Node: Sysval,  Next: Maketemp,  Prev: Esyscmd,  Up: Unix commands
  440. Exit codes
  441. ==========
  442.    To see whether a shell command succeeded, use `sysval':
  443.      sysval
  444. which expands to the exit status of the last shell command run with
  445. `syscmd' or `esyscmd'.
  446.      syscmd(`false')
  447.      =>
  448.      ifelse(sysval, 0, zero, non-zero)
  449.      =>non-zero
  450.      syscmd(`true')
  451.      =>
  452.      sysval
  453.      =>0
  454. File: m4.info,  Node: Maketemp,  Prev: Sysval,  Up: Unix commands
  455. Making names for temporary files
  456. ================================
  457.    Commands specified to `syscmd' or `esyscmd' might need a temporary
  458. file, for output or for some other purpose. There is a built-in macro,
  459. `maketemp', for making temporary file names:
  460.      maketemp(TEMPLATE)
  461. which expands to a name of a non-existent file, made from the string
  462. TEMPLATE, which should end with the string `XXXXXX'.  The six `X''s are
  463. then replaced, usually with something that includes the process id of
  464. the `m4' process, in order to make the filename unique.
  465.      maketemp(`/tmp/fooXXXXXX')
  466.      =>/tmp/fooa07346
  467.      maketemp(`/tmp/fooXXXXXX')
  468.      =>/tmp/fooa07346
  469.    As seen in the example, several calls of `maketemp' might expand to
  470. the same string, since the selection criteria is whether the file exists
  471. or not.  If a file has not been created before the next call, the two
  472. macro calls might expand to the same name.
  473. File: m4.info,  Node: Miscellaneous,  Next: Compatibility,  Prev: Unix commands,  Up: Top
  474. Miscellaneous built-in macros
  475. *****************************
  476.    This chapter describes various built-ins, that don't really belong in
  477. any of the previous chapters.
  478. * Menu:
  479. * Errprint::                    Printing error messages
  480. * M4exit::                      Exiting from m4
  481. File: m4.info,  Node: Errprint,  Next: M4exit,  Prev: Miscellaneous,  Up: Miscellaneous
  482. Printing error messages
  483. =======================
  484.    You can print error messages using `errprint':
  485.      errprint(MESSAGE, ...)
  486. which simply prints MESSAGE and the rest of the arguments on the
  487. standard error output.
  488.    The expansion of `errprint' is void.
  489.      errprint(`Illegal arguments to forloop
  490.      ')
  491.      error-->Illegal arguments to forloop
  492.      =>
  493.    A trailing newline is *not* printed automatically, so it must be
  494. supplied as part of the argument, as in the example.
  495.    To make it possible to specify the location of the error, two
  496. utility built-ins exist:
  497.      __file__
  498.      __line__
  499. which expands to the quoted name of the current input file, and the
  500. current input line number in that file.
  501.      errprint(`m4:'__file__:__line__: `Input error
  502.      ')
  503.      error-->m4:56.errprint:2: Input error
  504.      =>
  505. File: m4.info,  Node: M4exit,  Prev: Errprint,  Up: Miscellaneous
  506. Exiting from `m4'
  507. =================
  508.    If you need to exit from `m4' before the entire input has been read,
  509. you can use `m4exit':
  510.      m4exit(opt CODE)
  511. which causes `m4' to exit, with exit code CODE.  If CODE is left out,
  512. the exit code is zero.
  513.      define(`fatal_error', `errprint(`m4: '__file__: __line__`: fatal error: $*
  514.      ')m4exit(1)')
  515.      =>
  516.      fatal_error(`This is a BAD one, buster')
  517.      error-->m4: 57.m4exit: 5: fatal error: This is a BAD one, buster
  518.    After this macro call, `m4' will exit with exit code 1.  This macro
  519. is only intended for error exits, since the normal exit procedures are
  520. not followed, e.g., diverted text is not undiverted, and saved text
  521. (*note M4wrap::.) is not reread.
  522. File: m4.info,  Node: Compatibility,  Next: Concept Index,  Prev: Miscellaneous,  Up: Top
  523. Compatibility with other versions of `m4'
  524. *****************************************
  525.    This chapter describes the differences between this implementation of
  526. `m4', and the implementation found under Unix, notably System V,
  527. Release 3.
  528. * Menu:
  529. * Extensions::                  Extensions in GNU m4
  530. * Incompatibilities::           Facilities in System V m4 not in GNU m4
  531. * Other Incompat::              Other incompatibilities
  532. File: m4.info,  Node: Extensions,  Next: Incompatibilities,  Prev: Compatibility,  Up: Compatibility
  533. Extensions in GNU `m4'
  534. ======================
  535.    This version of `m4' contains a few facilities, that do not exist in
  536. System V `m4'.  These extra facilities are all suppressed by using the
  537. `-G' command line option, unless overridden by other command line
  538. options.
  539.    * In the `$'N notation for macro arguments, N can contain several
  540.      digits, while the System V `m4' only accepts one digit. This
  541.      allows macros in GNU `m4' to take any number of arguments, and not
  542.      only nine (*note Arguments::.).
  543.    * Files included with `include' and `sinclude' are sought in a user
  544.      specified search path, if they are not found in the working
  545.      directory.  The search path is specified by the `-I' option and the
  546.      `M4PATH' environment variable (*note Search Path::.).
  547.    * Arguments to `undivert' can be non-numeric, in which case the named
  548.      file will be included uninterpreted in the output (*note
  549.      Undivert::.).
  550.    * Formatted output is supported through the `format' built-in, which
  551.      is modeled after the C library function `printf' (*note Format::.).
  552.    * Searches and text substitution through regular expressions are
  553.      supported by the `regexp' and `patsubst' built-ins (*note
  554.      Regexp::. and *Note Patsubst::).
  555.    * The output of shell commands can be read into `m4' with `esyscmd'
  556.      (*note Esyscmd::.).
  557.    * There is indirect access to any built-in macro with `builtin'
  558.      (*note Builtin::.).
  559.    * Macros can be called indirectly through `indir' (*note Indir::.).
  560.    * The name of the current input file and the current input line
  561.      number are accessible through the built-ins `__file__' and
  562.      `__line__' (*note Errprint::.).
  563.    * The format of the output from `dumpdef' and macro tracing can be
  564.      controlled with `debugmode' (*note Debug Levels::.).
  565.    * The destination of trace and debug output can be controlled with
  566.      `debugfile' (*note Debug Output::.).
  567.    In addition to the above extensions, GNU `m4' implements the
  568. following command line options: `-V', `-d', `-l', `-o', `-N', `-I' and
  569. `-t'.  For a description of these options, *note Invoking m4::.
  570.    Also, the debugging and tracing facilities in GNU `m4' are much more
  571. extensive than in most other versions of `m4'.
  572. File: m4.info,  Node: Incompatibilities,  Next: Other Incompat,  Prev: Extensions,  Up: Compatibility
  573. Facilities in System V `m4' not in GNU `m4'
  574. ===========================================
  575.    The version of `m4' from System V contains a few facilities that
  576. have not been implemented in GNU `m4' yet.
  577.    * System V `m4' supports multiple arguments to `defn'.  This is not
  578.      implemented in GNU `m4'.  Its usefulness is unclear to me.
  579. File: m4.info,  Node: Other Incompat,  Prev: Incompatibilities,  Up: Compatibility
  580. Other incompatibilities
  581. =======================
  582.    There are a few other incompatibilities between this implementation
  583. of `m4', and the System V version.
  584.    * GNU `m4' implements sync lines differently from System V `m4',
  585.      when text is being diverted.  GNU `m4' outputs the sync lines when
  586.      the text is being diverted, and System V `m4' when the diverted
  587.      text is being brought back.
  588.      The problem is which lines and filenames should be attached to
  589.      text that is being, or has been, diverted.  System V `m4' regards
  590.      all the diverted text as being generated by the source line
  591.      containing the `undivert' call, whereas GNU `m4' regards the
  592.      diverted text as being generated at the time it is diverted.
  593.      Which is right?  I expect the sync line option to be used mostly
  594.      when using `m4' as a front end to a compiler.  If a diverted line
  595.      causes a compiler error, I believe that the error messages should
  596.      refer to the place where the diversion were made, and not where it
  597.      was inserted again.  Comments anyone?
  598.      Anyway, GNU `m4''s approach causes a serious bug, if calls to
  599.      undivert aren't alone on the input line.  See the file
  600.      `examples/divert.m4' for a demonstration of the bug.  I don't feel
  601.      it is acceptable to insert newlines in the output the user hasn't
  602.      asked for.
  603.    * GNU `m4' without `-G' option will define the macro `__gnu__' to
  604.      expand to the empty string.
  605.      On Unix systems, GNU `m4' without the `-G' option will define the
  606.      macro `__unix__', otherwise the macro `unix'.  Both will expand to
  607.      the empty string.
  608. File: m4.info,  Node: Concept Index,  Next: Macro Index,  Prev: Compatibility,  Up: Top
  609. Concept index
  610. *************
  611. * Menu:
  612. * Arguments to macros:                  Macro Arguments.
  613. * Arguments to macros:                  Arguments.
  614. * Arguments to macros, special:         Pseudo Arguments.
  615. * Arguments, quoted macro:              Quoting Arguments.
  616. * Arithmetic:                           Arithmetic.
  617. * Builtins, indirect call of:           Builtin.
  618. * Call of built-ins, indirect:          Builtin.
  619. * Call of macros, indirect:             Indir.
  620. * Changing comment delimiters:          Changecom.
  621. * Changing the quote delimiters:        Changequote.
  622. * Characters, translating:              Translit.
  623. * Command line, filenames on the:       Invoking m4.
  624. * Command line, macro definitions on the: Invoking m4.
  625. * Command line, options:                Invoking m4.
  626. * Commands, exit code from Unix:        Sysval.
  627. * Commands, running Unix:               Unix commands.
  628. * Comment delimiters, changing:         Changecom.
  629. * Comments:                             Comments.
  630. * Comments, copied to output:           Changecom.
  631. * Comparing strings:                    Ifelse.
  632. * Compatibility:                        Compatibility.
  633. * Conditionals:                         Ifdef.
  634. * Controlling debugging output:         Debug Levels.
  635. * Counting loops:                       Loops.
  636. * Debugging output, controlling:        Debug Levels.
  637. * Debugging output, saving:             Debug Output.
  638. * Decrement operator:                   Incr.
  639. * Defining new macros:                  Definitions.
  640. * Definitions, displaying macro:        Dumpdef.
  641. * Deleting macros:                      Undefine.
  642. * Deleting whitespace in input:         Dnl.
  643. * Discarding diverted text:             Cleardiv.
  644. * Displaying macro definitions:         Dumpdef.
  645. * Diversion numbers:                    Divnum.
  646. * Diverted text, discarding:            Cleardiv.
  647. * Diverting output to files:            Divert.
  648. * Error messages, printing:             Errprint.
  649. * Evaluation, of integer expressions:   Eval.
  650. * Executing Unix commands:              Unix commands.
  651. * Exit code from Unix commands:         Sysval.
  652. * Exiting from m4:                      M4exit.
  653. * Expansion of macros:                  Macro expansion.
  654. * Expansion, tracing macro:             Trace.
  655. * Expressions, evaluation of integer:   Eval.
  656. * Extracting substrings:                Substr.
  657. * File inclusion:                       File Inclusion.
  658. * File inclusion:                       Undivert.
  659. * Filenames, on the command line:       Invoking m4.
  660. * Files, diverting output to:           Divert.
  661. * Files, names of temporary:            Maketemp.
  662. * Forloops:                             Loops.
  663. * Formatted output:                     Format.
  664. * GNU extensions:                       Arguments.
  665. * GNU extensions:                       Search Path.
  666. * GNU extensions:                       Format.
  667. * GNU extensions:                       Builtin.
  668. * GNU extensions:                       Regexp.
  669. * GNU extensions:                       Esyscmd.
  670. * GNU extensions:                       Undivert.
  671. * GNU extensions:                       Debug Output.
  672. * GNU extensions:                       Extensions.
  673. * GNU extensions:                       Indir.
  674. * GNU extensions:                       Patsubst.
  675. * GNU extensions:                       Debug Levels.
  676. * Included files, search path for:      Search Path.
  677. * Inclusion, of files:                  File Inclusion.
  678. * Inclusion, of files:                  Undivert.
  679. * Increment operator:                   Incr.
  680. * Indirect call of built-ins:           Builtin.
  681. * Indirect call of macros:              Indir.
  682. * Input tokens:                         Syntax.
  683. * Input, saving:                        M4wrap.
  684. * Integer arithmetic:                   Arithmetic.
  685. * Integer expression evaluation:        Eval.
  686. * Length of strings:                    Len.
  687. * Loops:                                Loops.
  688. * Loops, counting:                      Loops.
  689. * Macro definitions, on the command line: Invoking m4.
  690. * Macro expansion, tracing:             Trace.
  691. * Macro invocation:                     Invocation.
  692. * Macros, arguments to:                 Macro Arguments.
  693. * Macros, arguments to:                 Arguments.
  694. * Macros, displaying definitions:       Dumpdef.
  695. * Macros, expansion of:                 Macro expansion.
  696. * Macros, how to define new:            Definitions.
  697. * Macros, how to delete:                Undefine.
  698. * Macros, how to rename:                Defn.
  699. * Macros, indirect call of:             Indir.
  700. * Macros, quoted arguments to:          Quoting Arguments.
  701. * Macros, recursive:                    Loops.
  702. * Macros, special arguments to:         Pseudo Arguments.
  703. * Macros, temporary redefinition of:    Pushdef.
  704. * Messages, printing error:             Errprint.
  705. * Multibranches:                        Ifelse.
  706. * Names:                                Names.
  707. * Options, command line:                Invoking m4.
  708. * Output, diverting to files:           Divert.
  709. * Output, formatted:                    Format.
  710. * Output, saving debugging:             Debug Output.
  711. * Pattern substitution:                 Patsubst.
  712. * Printing error messages:              Errprint.
  713. * Quote delimiters, changing the:       Changequote.
  714. * Quoted macro arguments:               Quoting Arguments.
  715. * Quoted string:                        Quoted strings.
  716. * Recursive macros:                     Loops.
  717. * Redefinition of macros, temporary:    Pushdef.
  718. * Regular expressions:                  Patsubst.
  719. * Regular expressions:                  Regexp.
  720. * Renaming macros:                      Defn.
  721. * Running Unix commands:                Unix commands.
  722. * Saving debugging output:              Debug Output.
  723. * Saving input:                         M4wrap.
  724. * Search path for included files:       Search Path.
  725. * Special arguments to macros:          Pseudo Arguments.
  726. * Strings, length of:                   Len.
  727. * Substitution by regular expression:   Patsubst.
  728. * Substrings, extracting:               Substr.
  729. * Temporary filenames:                  Maketemp.
  730. * Temporary redefinition of macros:     Pushdef.
  731. * Tokens:                               Syntax.
  732. * Tracing macro expansion:              Trace.
  733. * Translating characters:               Translit.
  734. * Undefining macros:                    Undefine.
  735. * Unix commands, exit code from:        Sysval.
  736. * Unix commands, running:               Unix commands.
  737. File: m4.info,  Node: Macro Index,  Prev: Concept Index,  Up: Top
  738. Macro index
  739. ***********
  740.    References are exclusively to the places where a built-in is
  741. introduced the first time.  Names starting and ending with `__' have
  742. these characters removed in the index.
  743. * Menu:
  744. * builtin:                              Builtin.
  745. * changecom:                            Changecom.
  746. * changequote:                          Changequote.
  747. * debugfile:                            Debug Output.
  748. * debugmode:                            Debug Levels.
  749. * decr:                                 Incr.
  750. * define:                               Define.
  751. * defn:                                 Defn.
  752. * divert:                               Divert.
  753. * divnum:                               Divnum.
  754. * dnl:                                  Dnl.
  755. * dumpdef:                              Dumpdef.
  756. * errprint:                             Errprint.
  757. * esyscmd:                              Esyscmd.
  758. * eval:                                 Eval.
  759. * file:                                 Errprint.
  760. * format:                               Format.
  761. * gnu:                                  Other Incompat.
  762. * ifdef:                                Ifdef.
  763. * ifelse:                               Ifelse.
  764. * include:                              Include.
  765. * incr:                                 Incr.
  766. * index:                                Index.
  767. * indir:                                Indir.
  768. * len:                                  Len.
  769. * line:                                 Errprint.
  770. * m4exit:                               M4exit.
  771. * m4wrap:                               M4wrap.
  772. * maketemp:                             Maketemp.
  773. * patsubst:                             Patsubst.
  774. * popdef:                               Pushdef.
  775. * pushdef:                              Pushdef.
  776. * regexp:                               Regexp.
  777. * shift:                                Loops.
  778. * sinclude:                             Include.
  779. * substr:                               Substr.
  780. * syscmd:                               Syscmd.
  781. * sysval:                               Sysval.
  782. * traceoff:                             Trace.
  783. * traceon:                              Trace.
  784. * translit:                             Translit.
  785. * undefine:                             Undefine.
  786. * undivert:                             Undivert.
  787. * unix:                                 Other Incompat.
  788.